package com.etc.demo1.demo.mapper;

import com.etc.demo1.demo.domain.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserMapper {
    //新增数据
    @Insert("INSERT INTO user_info(user_info.user_phone,user_info.user_password,user_info.user_judg) VALUES (#{name},#{password},0)")
    int saveUser(@Param("name") int name,@Param("password") String password);

    //查找数据
    @Select("SELECT * FROM user_info WHERE user_phone=#{name} AND user_password='#{password}'")
    User selectUser(@Param("name") int name,@Param("password") String password);

    //删除数据
    @Delete("delete from user_info where user_id=#{id}")
    public int delete(int id);

    //查询全部
    @Select("select * from user_info")
    List<User> findAll();

    //根据id查找
    @Select("select * from user where id=#{id}")
    public User getUserById(int id);

    //更新数据（顾客）
    @Update("update user set user_name=#{username},user_password=#{userpassword},user_sex=#{usersex},user_age=#{userage},user_phone=#{userphone},user_judg=0 where user_id=#{id}")
    public int Update1(User user);

    //更新数据（管理员）
    @Update("update user set user_name=#{username},user_password=#{userpassword},user_sex=#{usersex},user_age=#{userage},user_phone=#{userphone},user_judg=1 where user_id=#{id}")
    public int Update2(User user);

    int saveUser(User user);
}
